package org.langqiao.genericity;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Date;
import java.util.Vector;




public class GenericityApply {
	public static void main(String[] args) throws NoSuchMethodException, SecurityException {
		//swap(new String[]{"a","b","c"}, 1, 2);
		//swap(new Integer[]{1,2,3}, 1, 2);
		Number str = add(3, 3.5);
		Object obj = add("abc", 3);
		Method method = GenericityApply.class.getMethod("applyVector", Vector.class);
		Type[] types = method.getGenericParameterTypes();
		ParameterizedType parameterizedType = (ParameterizedType) types[0];
		System.out.println(parameterizedType.getRawType());
		System.out.println(parameterizedType.getActualTypeArguments()[0]);
	}
	
	public static <T> void swap(T[] t,int x,int y){
		T tmp = t[x];
		t[x] = t[y];
		t[y] = tmp;
	}
	
	public static <T> T add(T x,T y){
		return null;
	}
	
	public static void printCollection(Collection<?> collection){
		System.out.println(collection.size());
		for(Object obj :collection){
			System.out.println(obj);
		}
	}
	
	public static void applyVector(Vector<Date> v){
		
	}
}
